package com.simple.dispatcher.servlet.utils;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

public class RequestParamUtils {

	public static long getLongValue(HttpServletRequest req, String name, long defaultValue) {
		long result = defaultValue;
		String v = req.getParameter(name);
		if(StringUtils.isNotEmpty(v)){
			try{
				result = Long.parseLong(v);
			}catch (NumberFormatException e) {
			}
		}
		return result;
	}
	
	public static String getStringValue(HttpServletRequest req, String name, String defaultValue){
		String result = defaultValue;
		String v = req.getParameter(name);
		if(StringUtils.isNotEmpty(v)){
			result = v;
		}
		return result;
	}
	
	public static String[] getStringValues(HttpServletRequest req, String name, String defaultValues[]){
		String[] result = defaultValues;
		String[] v = req.getParameterValues(name);
		if(v!=null && v.length>0){
			result = v;
		}
		return result;
	}
}
